-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hack/verify-staging-imports.sh: print actual dependencies #40659
hack/verify-staging-imports.sh: print actual dependencies #40659
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED Needs approval from an approver in each of these OWNERS Files: We suggest the following people: |
@k8s-bot unit test this |
@@ -25,8 +25,20 @@ kube::golang::setup_env | |||
|
|||
|
|||
for dep in $(ls -1 ${KUBE_ROOT}/staging/src/k8s.io/); do | |||
if go list -f {{.Deps}} ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -e "."; then | |||
echo "${dep} has a cyclical dependency" | |||
if go list -f "{{.Deps}}" ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -qe "."; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to extract the printing logic so we can reasonably prevent client-go from depending on apiserver without copy/pasting this monster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
certainly this can be abstracted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
certainly this can be abstracted.
Ok, I'm bash challenged. You mind setting it up and then this lgtm.
if go list -f "{{.Deps}}" ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -qe "."; then | ||
echo "${dep} has a cyclical dependency:" | ||
echo | ||
go list -f '{{.ImportPath}} {{.Deps}}' ./vendor/k8s.io/${dep}/... | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt @stevekuznetsov @smarterclayton @ncdc I feel like this deserves some honorable mention or something for most sed
pipes I've been in our bash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely there is a cleaner and more approachable way to do this using the Golang AST API... @deads2k you owe me lunch for making this the first thing I looked at this morning
go list -f '{{.ImportPath}} {{.Deps}}' ./vendor/k8s.io/${dep}/... | | ||
sed 's|^k8s.io/kubernetes/vendor/\([-a-zA-Z./0-9_]*\)|\1:|' | # remove vendor prefix of ImportPath | ||
sed 's| k8s.io/kubernetes/vendor/[-a-zA-Z./0-9_]*||g' | # remove vendored packages | ||
grep k8s.io/kubernetes | # only show packages with k8s.io/kubernetes deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you put in newlines laters, how is grep
working right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if one k8s.io/kubernetes is found it's enough to consider the whole line. If not, ignore the whole line.
I'm confident it still exits 1 when it fails. I'm unsure about the pipe monster and a little concerned about finding internal cycles. Is there an easy way to make it workable for client-go to apiserver style deps? |
49642ac
to
3e58f7c
Compare
Updated, still WIP. Stepping out for an hour, then testing. |
72c26d6
to
ea79fe5
Compare
ea79fe5
to
78e7e51
Compare
@deads2k @stevekuznetsov ptal. #40688 is supposed to fail. |
I still don't understand why this is a Bash script. The Go team exposes a great library for programatically working with Go source. Writing a short Go script using |
@stevekuznetsov feel free to rewrite it in Go as a follow-up. IMO it's not really important for this tiny script. We have bash code (look into Makefile.generated_files for instance) which is 3 orders of magnitude more awful and worth the energy spent for a rewrite. |
fi | ||
done | ||
RC=0 | ||
print_forbidden_imports apimachinery k8s.io/ || RC=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this ended up a lot better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If at any point you expect set -o errexit
to alter the flow of commands inside of print_forbidden_imports
-- like, a failure somewhere in there you would expect to exit early ... in this construct, it would not. function_call || something
will turn off errexit
inside the function and there is no way to turn it back on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. thanks. Those details of shell code...
shift | ||
local RE="" | ||
local SEP="" | ||
for CLAUSE in "$@"; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this pick up the first argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shift
above removes it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the shift on line 28
lgetm. |
@eparis don't freak out this time. I'm going to open a pull to add myself to the list |
@deads2k RAWR! |
78e7e51
to
22e9db0
Compare
Automatic merge from submit-queue (batch tested with PRs 40703, 40093, 40618, 40659, 39810) |
Example: